<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="ihis.model.*" %>
<%@ page import="ihis.core.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@page import="ihis.tms.client.IHISTMSClient"%>

<%@ include file="filter.jsp" %>
    
<%
	TaskFilter taskFilter = new TaskFilter(filter);
	taskFilter.setStartDate(null);
	ProjectScheduleRiskReport report = (ProjectScheduleRiskReport) core.getReport(IHISConstants.REPORT_RISK, taskFilter);
	List<TeamRisk> teamRisks = report.getTeamRiskList();
	
	// 샘플 데이터  
	
	for(int i=0; i<10; i++){
		TeamRisk r = new TeamRisk();
		r.setDelayedRiskCnt(((int) (20*Math.random()) +1 ));
		r.setPotentialRiskCnt(((int) (20*Math.random()) +1 ));
		r.setTeamId("" + ((int) (5*Math.random()) +1 ));
		r.setProjectId("" + ((int) (3*Math.random()) +1 ));
		teamRisks.add(r);
	}
	
	//  샘플 데이터 끝 
%>


<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Predicted Curve Report</title>
    <link rel="stylesheet" href="script/jquery.mobile-1.0a4.1.min.css"/>
    <link rel="stylesheet" href="script/layout.css"/>
    <link rel="stylesheet" href="script/ihis.css"/>
    <script src="script/jquery-1.6.min.js"></script>
    <script src="script/jquery.flot.min.js"></script>
    <script src="script/jquery.flot.resize.min.js"></script>
    <script src="script/jquery.flot.stack.min.js"></script>
    <script src="script/ihis.schedule.js"></script>
    <script src="script/jquery.mobile-1.0a4.1.min.js"></script>
       <style type="text/css">
    html, body {
        height: 100%; /* make the percentage height on placeholder work */
    }
    </style>
</head>

<body>
	<div id="predictedCurvePage" data-role="page" style="height: 100%">
		<div data-role="header" data-position="fixed">
			<a href="#" data-icon="back" data-role="button" id="backButton">Back</a>
			<h1>조직 일정 위험 챠트</h1>
			<a href="#" data-icon="home" data-role="button" id="homeButton">Home</a>
		</div>

		<div data-role="content" style="height: 70%">
		    <div id="placeholder" style="width:98%;height:60%;"></div>

<%
	StringBuilder value1 = new StringBuilder(); // 지연 개수 
	StringBuilder value2 = new StringBuilder(); // 잠재 개수 
	StringBuilder value3 = new StringBuilder(); // 팀명 약어 (숫자) 
	StringBuilder value4 = new StringBuilder(); // 실제 팀명  
	
	value1.append("[");
	value2.append("[");
	value3.append("[");
	value4.append("Legend :<br/>");
	char name = 'A';
	for(int i=0; i<teamRisks.size(); i++){
		TeamRisk tr = teamRisks.get(i);
		
		if(i != 0){
			value1.append(", ");
			value2.append(", ");
			value3.append(", ");
			value4.append(", ");
		}
		String tempTeamName = tms.getTeamName(tr.getTeamId());
		value1.append("[").append(i + 1).append(", \"").append(name).append("\"]");
		value2.append("[").append(i + 1).append(", ").append(tr.getDelayedRiskCnt()).append("]");
		value3.append("[").append(i + 1).append(", ").append(tr.getPotentialRiskCnt()).append("]");
		value4.append(name++).append("(").append(tempTeamName).append(")");
	}
	value1.append("]");
	value2.append("]");
	value3.append("]");
%>

<script type="text/javascript">
$(function () {
    var placeholder = $("#placeholder");
    
    var data = 
    	[
    	 	{label: 'Delayed Task Count', data: <%= value2.toString() %>},
    	 	{label: 'Potential Task Count', data: <%= value3.toString() %>},
        ];
    
    var options =
    	{
    		series:
    			{
    				stack: 0,
    				lines: {show: false, steps: false},
    				bars: {show: true, barWidth: 0.5, align: "center"}
    			},
   			xaxis: 
   				{
   					ticks: <%= value1.toString() %>
    			}
    	};
    
    var plot = $.plot(placeholder, data, options);
    
    placeholder.resize(function () {
        $(".message").text("Placeholder is now "
                           + $(this).width() + "x" + $(this).height()
                           + " pixels");
    });
});
</script>
<%
	StringBuilder sb = new StringBuilder("Filter :<br/>");
	if(!IHISUtil.isEmpty(startDate)){
		sb.append(startDate).append(" ");
	}
	if(!IHISUtil.isEmpty(endDate)){
		sb.append("~").append(endDate).append(" ");
	}
	if(!IHISUtil.isEmpty(user)){
		sb.append("/ ").append(userName).append("(").append(user).append(") " );
	}
	if(!IHISUtil.isEmpty(team)){
		sb.append("/ ").append(teamName).append(" ");
	}
	if(!IHISUtil.isEmpty(project)){
		sb.append("/ ").append(projectName).append(" ");
	}
	
%>
			<h6><%= value4.toString() %></h6>
			<h5><%= sb.toString() %></h5>
		</div> 

	<script type="text/javascript">
    	$(function(){
    		$("#searchButton").bind("click", function(){
				<% 
					StringBuilder url = new StringBuilder("searchSchedule.jsp?filterFor=predictedCurve");
					url.append("&periodType=").append("" + filter.getPeriodType());
					url.append("&ownerType=").append("" + filter.getOwnerType());

					if(filter.getStartDate() != null){
						url.append("&").append("startDate=").append(new SimpleDateFormat("yyyy-MM-dd").format(filter.getStartDate()));
					}
					if(filter.getEndDate() != null){
						url.append("&").append("endDate=").append(new SimpleDateFormat("yyyy-MM-dd").format(filter.getEndDate()));
					}
					if(!IHISUtil.isEmpty(filter.getUserId())){
						url.append("&").append("user=").append(filter.getUserId());
					}
					if(!IHISUtil.isEmpty(filter.getProjectId())){
						url.append("&").append("project=").append(filter.getProjectId());
					}
					if(!IHISUtil.isEmpty(filter.getTeamId())){
						url.append("&").append("team=").append(filter.getTeamId());
					}
				%>
				var url = "<%= url %>";
				document.location = url;
    		});
    	});
    	// 1. page 로 지정된 ID 값,  2.효과 3. 방향 :  false(>), true(<)
    </script>		
		
		<div data-role="footer">
			<a href="" id="searchButton" data-icon="check"  data-transition="slideup">Search</a>
			<a href="javascript:window.location.reload(true)" data-icon="refresh" data-rel="refresh" data-transition="flip">Refresh</a>
		</div>
		
	</div>
	
	<!-- 검색 정보를 저장해둔다. : Task 목록을 위해 사용 -->
	<div>
		<form action="#" method="post" name="filterForm">
			<input type="hidden" name="startDate" value="<%= startDate%>"/>
			<input type="hidden" name="endDate" value="<%= endDate%>"/>
			<input type="hidden" name="periodType" value="<%= periodType%>"/>
			<input type="hidden" name="user" value="<%= user%>"/>
			<input type="hidden" name="team" value="<%= team%>"/>
			<input type="hidden" name="ownerType" value="<%= ownerType%>"/>
			<input type="hidden" name="taskType" value=""/>
		</form>
	</div>
</body>
</html>